package com.z.sys.controller;

import com.github.pagehelper.PageInfo;
import com.z.sys.entity.UserPermissionSort;
import com.z.common.web.base.BaseController;
import com.z.common.web.vo.request.PageVo;
import com.z.common.aop.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import com.z.common.aop.enums.BusinessType;
import com.z.common.web.vo.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.z.sys.service.IUserPermissionSortService;
import org.springframework.web.servlet.ModelAndView;
import java.util.Arrays;

/**
 * 快捷入口Controller
 *
 * @author z
 * @date 2024-01-03
 */
@Api(tags = "快捷入口")
@RestController
@RequestMapping("/system/userPermissionSort")
public class UserPermissionSortController extends BaseController {

    private String prefix = "system/userPermissionSort";

    @Autowired
    private IUserPermissionSortService userPermissionSortService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/system/userPermissionSort/main','sys:userPermissionSort:main')")
    @ApiOperation(value = "查询页面")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询快捷入口列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/system/userPermissionSort/data','sys:userPermissionSort:main')")
    @Log(title = "快捷入口", describe = "查询快捷入口列表", type = BusinessType.QUERY)
    @ApiOperation(value = "查询接口")
    public Result list(@ModelAttribute UserPermissionSort userPermissionSort, PageVo pageVo) {
        PageInfo<UserPermissionSort> pageInfo = userPermissionSortService.selectUserPermissionSortPage(userPermissionSort, pageVo);
        return Result.table(pageInfo);
    }

    /**
     * 新增快捷入口
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/system/userPermissionSort/add','sys:userPermissionSort:add')")
    @ApiOperation(value = "添加页面")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增快捷入口
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/system/userPermissionSort/save','sys:userPermissionSort:add')")
    @Log(title = "快捷入口", describe = "新增快捷入口数据", type = BusinessType.ADD)
    @ApiOperation(value = "添加接口")
    public Result save(@RequestBody UserPermissionSort userPermissionSort) {
        return Result.decide(userPermissionSortService.save(userPermissionSort));
    }

    /**
     * 修改快捷入口
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/system/userPermissionSort/edit','sys:userPermissionSort:edit')")
    @ApiOperation(value = "修改页面")
    public ModelAndView edit(Long id, ModelMap map) {
        UserPermissionSort userPermissionSort =userPermissionSortService.getById(id);
        map.put("userPermissionSort", userPermissionSort);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改快捷入口
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/system/userPermissionSort/update','sys:userPermissionSort:edit')")
    @Log(title = "快捷入口", describe = "修改快捷入口数据", type = BusinessType.EDIT)
    @ApiOperation(value = "修改接口")
    public Result update(@RequestBody UserPermissionSort userPermissionSort) {
        return Result.decide(userPermissionSortService.updateById(userPermissionSort));
    }

    /**
     * 删除快捷入口
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/system/userPermissionSort/batchRemove','sys:userPermissionSort:del')")
    @Log(title = "快捷入口", describe = "删除快捷入口数据", type = BusinessType.REMOVE)
    @ApiOperation(value = "批量删除接口")
    public Result batchRemove(String ids) {
        return Result.decide(userPermissionSortService.removeByIds(Arrays.asList(ids.split(","))));
    }

    /**
     * 删除快捷入口
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/system/userPermissionSort/remove','sys:userPermissionSort:del')")
    @Log(title = "快捷入口", describe = "删除快捷入口数据", type = BusinessType.REMOVE)
    @ApiOperation(value = "删除接口")
    public Result remove(@PathVariable("id") Long id) {
        return Result.decide(userPermissionSortService.removeById(id));
    }
}
